<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
    request.setCharacterEncoding("UTF-8");
    String htmlData = request.getParameter("content1") != null ? request.getParameter("content1") : "";
%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <script type="text/javascript" src="<%=path%>/My97DatePicker/WdatePicker.js"></script>
    <link rel="stylesheet" type="text/css" href="<%=path%>/CSS/backLayout.css">
    <style type="text/css">
        input[type=checkbox] {
            padding: 0px;
            margin: 0px;
            text-align: right;
            width: 15px
        }

        .div_zilei {
            width: 600px;
            padding-left: 90px;
            height: 30px
        }

        .tr {
            height: 40px;
            background: #a9bbe0
        }

        .tr td {
            font-size: 14px;
            color: #ffffff
        }

        .tr_td {
            height: 40px;
        }

        .tr_td td {
            border-bottom: 1px solid #ededed;
            text-align: center;
        }

        tr td:nth-child(1) {
            font-size: 14px;
            color: #cccccc
        }

        .date {
            border: 0;
            background: #ffffff;
            text-align: center;
        }

        .tr_td td:nth-child(1) {
            border-left: 1px solid #cccccc;
        }

        .addTable.deleteTable:HOVER {
            cursor: pointer;
        }

        .fseq {
            width: 37px;
            border: 0;
            text-align: center;
            color: #cccccc
        }

        .jczl {
            padding-left: 100px;
        }

        .div_tj {
            margin-top: 40px;
            padding-right: 60px;
        }

        .text {
            border: 0;
            background: #ffffff;
            text-align: center;
        }

    </style>
</head>
<body style="background: #f5f5f5">
<div class="main">
    <div class="weizhi">
        <c:if test="${xqid==null}">
            基础资料>>财务基础资料>>协议驾校>>修改
        </c:if>
        <c:if test="${xqid!=null}">
            基础资料>>财务基础资料>>协议驾校>>查看
        </c:if>
    </div>
    <div class="div_body" style="height: 1000px;box-shadow: 0 0 5px #cccccc;">
        <c:if test="${xqid == null}">
            <div class="div_form">
                <input id="fid" type="text" name="fid" style="visibility:hidden" value="${driving.fid}"/>
                <div class="jczl">
                    <div class="div_input">
                        <span class="gn_name">财务组织&nbsp;:&nbsp;</span>
                        <input type="text" readonly="readonly" name="fcontrolunitid" value="${department}"
                               style="color: gray;">
                    </div>
                    <div class="div_input">
                        <span class="gn_name">编码&nbsp;:&nbsp;</span>
                        <input id="fnumber" type="text" name="fnumber" readonly="readonly" value="${driving.fnumber}"
                               style="color: gray;">
                    </div>
                    <div class="div_input">
                        <span class="gn_name">名称&nbsp;:&nbsp;</span>
                        <input id="fnameL2" class="is_click" type="text" name="fnameL2" value="${driving.fnameL2}">
                        <span class="required">必填</span>
                    </div>
                    <div class="div_input">
                        <span class="gn_name">简称&nbsp;:&nbsp;</span>
                        <input id="fsimplename" type="text" name="fsimplename" value="${driving.fsimplename}">
                    </div>
                    <div class="div_input">
                        <span class="gn_name">描述&nbsp;:&nbsp;</span>
                        <input id="fdescriptionL2" type="text" name="fdescriptionL2" value="${driving.fdescriptionL2}"
                               id="gs">
                    </div>

                    <div class="div_zilei">
                        <div style="width: 380px;text-align: right;float: left;">
                            <img src="<%=path%>/image/insert2323.jpg" class="addTable">
                            <span style="padding-right: 20px;color: #a9bbe0;font-size: 14px" class="addTable">添加</span>
                            <img src="<%=path%>/image/delete212.png" class="deleteTable">
                            <span class="deleteTable" style="color: #a9bbe0;font-size: 14px"
                                  class="deleteTable">删除</span>
                        </div>
                    </div>
                    <div style="overflow:auto;height: 230px;width: 600px;">
                        <table width="100%" id="table1"
                               style="min-height:50px;overflow:hidden;border-spacing:0;">
                            <tr class="tr">
                                <td width="45px" align="center" class='fseq'>序号</td>
                                <td width="150px" align="center">车牌</td>
                                <td width="150px" align="center">车型</td>
                                <td width="150px" align="center">备注</td>
                            </tr>
                            <c:forEach items="${drivingentrysList}" var="drivingentrys" varStatus="s">
                                <tr align="left" class="tr_td">
                                    <td style="display: none">
                                        <input type="text" name="did" value="${drivingentrys.fid}"/>
                                    </td>
                                    <td>
                                        <input type="text" class="fseq" name="fseq" value="${drivingentrys.fseq + 1}"
                                               readonly='readonly'>
                                    </td>
                                    <td>
                                        <input type="text" name="car_input1" class="text"
                                               value="${drivingentrys.cfchepiao}"/>
                                    </td>
                                    <td>
                                        <input type="text" name="car_input2" class="text"
                                               value="${drivingentrys.cfchexing}"/></td>
                                    <td>
                                        <input type="text" name="car_input3" class="text"
                                               value="${drivingentrys.cfdesc}"/></td>
                                </tr>
                            </c:forEach>
                        </table>
                    </div>
                </div>
                <div class="div_tj">
                    <div>
                        <input type="submit" class="input_submit bc" value="">
                    </div>
                    <div>
                        <input type="button" class="input_back fh" value="" onclick="back()"/>
                    </div>
                </div>
            </div>
        </c:if>
        <c:if test="${xqid != null}">
            <div class="div_form">
                <input id="fid" type="text" name="fid" style="visibility:hidden" value="${driving.fid}"/>
                <div class="jczl">
                    <div class="div_input">
                        <span class="gn_name">财务组织&nbsp;:&nbsp;</span>
                        <input type="text" readonly="readonly" name="fcontrolunitid" value="${department}"
                               style="color: gray;">
                    </div>
                    <div class="div_input">
                        <span class="gn_name">编码&nbsp;:&nbsp;</span>
                        <input id="fnumber" type="text" name="fnumber" readonly="readonly" value="${driving.fnumber}"
                               style="color: gray;">
                    </div>
                    <div class="div_input">
                        <span class="gn_name">名称&nbsp;:&nbsp;</span>
                        <input id="fnameL2" class="is_click" readonly="readonly" type="text" name="fnameL2"
                               value="${driving.fnameL2}">
                    </div>
                    <div class="div_input">
                        <span class="gn_name">简称&nbsp;:&nbsp;</span>
                        <input id="fsimplename" readonly="readonly" type="text" name="fsimplename"
                               value="${driving.fsimplename}">
                    </div>
                    <div class="div_input">
                        <span class="gn_name">描述&nbsp;:&nbsp;</span>
                        <input id="fdescriptionL2" readonly="readonly" type="text" name="fdescriptionL2"
                               value="${driving.fdescriptionL2}"
                               id="gs">
                    </div>

                    <div style="overflow:auto;height: 230px;width: 860px;">
                        <table width="100%" id="table1"
                               style="min-height:50px;overflow:hidden;border-spacing:0;">
                            <tr class="tr">
                                <td class="did"></td>
                                <td width="84px" align="center">车牌</td>
                                <td width="84px" align="center">车型</td>
                                <td width="84px" align="center">备注</td>
                            </tr>
                            <c:forEach items="${drivingentrysList}" var="drivingentrys" varStatus="s">
                                <tr align="left" class="tr_td">
                                    <td class="did">
                                        <input style="width: 40px;" type="text" name="fseq" class="fseq"
                                               value="${s.index}"
                                               readonly='readonly'>
                                    </td>
                                    <td>
                                        <input type="text" name="cfchepiao" class="text"
                                               id="cfexercisedate${drivingentrys.fseq}"
                                               value="${drivingentrys.cfchepiao}" readonly='readonly'/>
                                    </td>
                                    <td>
                                        <input type="text" name="cfchexing" class="text"
                                               id="cfendtime${drivingentrys.fseq}"
                                               value="${drivingentrys.cfchexing}" readonly='readonly'/></td>
                                    <td>
                                        <input type="text" name="cfdesc" class="text"
                                               id="cfendtime${drivingentrys.fseq}"
                                               value="${drivingentrys.cfdesc}" readonly='readonly'/></td>
                                </tr>
                            </c:forEach>
                        </table>
                    </div>
                </div>
                <div class="div_tj">
                    <div>

                    </div>
                    <div>
                        <input type="button" class="input_back fh" value="" onclick="back()"/>
                    </div>
                </div>
            </div>
        </c:if>

    </div>
</div>
</body>
<script type="text/javascript" src="<%=path%>/JQuery/jquery-1.8.2.js"></script>
<script>
    var updateid = new Array();

    $(".addTable").click(function () {
        var tr_len = $("#table1 tr").length;//表格长度
        var str = "<tr align='left' class='tr_td'><td><input type='text' name='fseq' class='fseq' value=" + tr_len + " readonly='readonly'></td>"
        str += "<td><input type='text' name='car_input1' class='text'/></td>"
        str += "<td><input type='text' name='car_input2' class='text'/></td>"
        str += "<td><input type='text' name='car_input3' class='text'/></td></tr>"
        $("#table1").append(str)
    })

    //删除一行
    $(".deleteTable").click(function () {
        var tr_len = $("#table1 tr").length;
        if (tr_len == 2) {
            alert("最后一条不能删除")
        } else {
            updateid.push($('#table1 tr:last').find('td input:first').val());
            $('#table1 tr:last').remove();
        }
    })

    $(".input_submit").click(function () {

        var fid = $("#fid").val();//fid
        var fnumber = $("#fnumber").val();//名称
        var fnameL2 = $("#fnameL2").val();//名称
        var fsimplename = $("#fsimplename").val();//简称
        var fdescriptionL2 = $("#fdescriptionL2").val();//描述

        var cfchepiao = new Array();
        var cfchexing = new Array();
        var cfdesc = new Array();
        var didarr = new Array();//车辆的fid
        var fseqarr = new Array();//车辆的fid

        var car_input1 = document.getElementsByName("car_input1");
        var car_input2 = document.getElementsByName("car_input2");
        var car_input3 = document.getElementsByName("car_input3");
        var did = document.getElementsByName("did");
        var fseq = document.getElementsByName("fseq");

        /*只遍历改变了的数据*/
        for (var i = 0; i < car_input1.length; i++) {
            cfchepiao[i] = car_input1[i].value;
            cfchexing[i] = car_input2[i].value;
            cfdesc[i] = car_input3[i].value;
            if (typeof(did[i]) != "undefined")
            didarr[i] = did[i].value;
            fseqarr[i] = fseq[i].value;
        }

        if ($('.is_click').val() == "") {
            alert('必填项不能为空！');
            return false;
        }

        location = 'update_driving?fseq=' + fseqarr + '&updateid=' + updateid + '&did=' + didarr + '&fid=' + fid + '&fnumber=' + fnumber + '&fnameL2=' + fnameL2 + '&fsimplename=' + fsimplename + '&fdescriptionL2='
            + fdescriptionL2 + '&cfchepiao=' + cfchepiao + '&cfchexing=' + cfchexing + '&cfdesc=' + cfdesc + '';
    });

    //返回
    function back() {
        parent.closeSelectCard()

//        location = '<%=path%>/DrivingSys/select_driving/look.action'
    }

</script>
<%@ include file="/WEB-INF/JSP/ajax.jsp" %>
</html>